package com.woniuxy.micromessageserver.messagemag.mapper;


import com.woniuxy.micromessageserver.bean.NewsBean;
import com.woniuxy.micromessageserver.bean.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface NewsMapper {

    //1增加一条消息
    @Insert("insert into t_news_info(news_title,news_content,news_type,news_time,news_status,fk_user_id)" +
            "values (#{n.newsTitle},#{n.newsContent},#{n.newsType}," +
            "now(),'0',#{n.userId})")
    int saveNewsBean(@Param("n")NewsBean newsBean);


    //2将传入id的消息从未读改为已读
    @Update("update t_news_info set news_status=1 where id = #{id}")
    int updateNews(@Param("id")Long id);


    //3查询消息 根据消息类型  分页 查询的消息都是当前用户的消息userId要匹配,分为三种消息类型
    List<NewsBean> findNewsByUidAndType(@Param("p")PageRequest request, @Param("n")NewsBean newsBean);

    //4根据消息id查询消息
    @ResultType(NewsBean.class)
    @Select("select id,news_title as newsTitle," +
            "news_content as newsContent," +
            "news_type as newsType,news_time as newsTime," +
            "news_status as newsStatus,fk_user_id as userId from t_news_info where id = #{id}")
    NewsBean findByNewsId(Long id);


}
